﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Linq.SqlClient;

namespace PHTShop.admin
{
    public partial class Listuser : System.Web.UI.Page
    {
        private void loaddata()
        {
            DataContextDataContext dc = new DataContextDataContext();
            if (Request.Form["user"].ToString().Equals("") || Request.Form["user"] == null)
            {
                lsv.DataSource = dc.Accounts.Where(acc => acc.roleId == 2).ToList();
                lsv.DataBind();
            }
            else
            {
                var db = dc.Accounts.Where(acc => acc.roleId == 2 && SqlMethods.Like(acc.username, "%" + Request.Form["user"].ToString() + "%")).ToList();
                if (db.Count > 0)
                {
                    lsv.DataSource = db;
                    lsv.DataBind();
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                loaddata();
            }
        }
        protected void lsv_SelectedIndexChanged(object sender, EventArgs e)
        {
            int userid = 0;
            userid = Convert.ToInt32((lsv.Items[lsv.SelectedIndex].FindControl("hdfUserID") as HiddenField).Value);
            Response.Redirect("CustomerOrdered.aspx?id=" + userid);
        }
        protected void lsv_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
        {

        }

        protected void lsv_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
        {
            DataPager1.SetPageProperties(e.StartRowIndex, 10, false);
            loaddata();
        }
    }
}